package com.zyj.rabbitmq.controller;

import com.zyj.rabbitmq.config.RabbitConfig;
import com.zyj.rabbitmq.send.Sender;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zyj
 * @date 2018-08-07
 */
@RestController
public class RabbitmqController {

    @Autowired
    public AmqpTemplate amqpTemplate;

    @Autowired
    private Sender sender;


    @GetMapping("/rabbitmq/helloTest")
    public void helloTest(){
        System.out.println("开始发送消息。。。。。。。。。。。。。。");
        sender.send();
    }

    /**
     * p2p模式
     * 一对一
     */
    @GetMapping("/rabbitmq/p2pQueue")
    public void p2pQueue(){
        System.out.println("开始发送消息。。。。。。。。。。。。。。");
        sender.p2pSend();
    }

    /**
     * fanout模式（类似一对多）
     */
    @GetMapping("/rabbitmq/fanout")
    public void fanout(){
        Object message = "fanout模式";
        sender.sendFanout(message);
    }

    /*************topic模式测试**************/
    @GetMapping("/rabbitmq/sendAll")
    public void sendAll(){
        amqpTemplate.convertAndSend(RabbitConfig.EXCHANGE_NAME_TOPIC, "topic.test", "send All");
    }

    @GetMapping("/rabbitmq/sendTopic")
    public void sendTopic(){
        amqpTemplate.convertAndSend(RabbitConfig.EXCHANGE_NAME_TOPIC, RabbitConfig.TOPIC, "send Topic");
    }

    @GetMapping("/rabbitmq/sendTopicA")
    public void sendTopicA(){
        amqpTemplate.convertAndSend(RabbitConfig.EXCHANGE_NAME, RabbitConfig.TOPIC_A, "send TopicA");
    }

    /****************延迟消费******************/
    @GetMapping("/rabbitmq/sendLazy")
    public void sendLazy(){
        Object message = "延迟发送";
        sender.sendLazy(message);
    }


}
